package main

func main() {
	println(thirdMax([]int{2, 2, 3, 1}))
}
func thirdMax(nums []int) int {
	max := -4353564672
	second := -4353564672
	third := -4353564672

	for _, num := range nums {
		if num == max || num == second || num == third {
			continue
		}
		if num > max {
			max, second, third = num, max, second
			continue
		} else if num < max && num > second {
			second, third = num, second
			continue
		} else if num < second && num >= third {
			third = num
			continue
		} else {
			continue
		}
	}
	if third != -4353564672 {
		return third
	}
	return max
}
